<!--Generate by Kevin's CodeBuilder -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>bui-ssm快速开发框架</title>
<head th:include="source::header"></head>
<style type="text/css">
body {
	padding: 6px 6px;
}

#addRoot {
	text-decoration: underline;
	cursor: pointer;
}
</style>
</head>
<body>
	<div>
		<a id="addRoot">[(${Lang.menu_addRoot})]</a>
	</div>
	<div style="padding-left: 30px">
		<ul id="tree"></ul>
	</div>
	<script type="text/javascript">
		var win,tree,rootId,$tree,height = 450;
		var curdObj = {
			add:function(data){				
				$B.request({
					data:data,
					url:$B.getHttpHost(ctxPath) + "menu/add",
					ok:function(message, data){
						win.close();
						queryTree(rootId);
					}
				});
			},
			update:function(data){
				$B.request({
					data:data,
					url:$B.getHttpHost(ctxPath) + "menu/update",
					ok:function(message, data){
						win.close();
						queryTree(rootId);
					}
				});
			},
			closeWindow:function(){
				win.close();
			}
		};
		var title = "[(${Lang.menu_windowTitle})]";//国际化语言
		//打开form.html
		function _openForm(prs,isUpdate){
			var url = $B.getHttpHost(ctxPath) + "menu/page/form";
			if(isUpdate){
				url = url + "?id="+prs.id;
			}else{
				url = url + "?pid="+prs.id;
			}
			var opts = {
				dataType:'html',
				title:title + "["+prs.data.menuText+"]",
				width:700,
				height:height,
				content: url 
			};			
			win = $B.window(opts);
		};
		
		window["toolbarMethods"] = {
			addFn:function(prs){
				_openForm(prs);
			},
			updateFn:function(prs){
				_openForm(prs,true);
			},
			deleteFn:function(prs){
				$B.confirm({
					message:'[(${Lang.menu_deleteConfirm})]',
					okFn:function(){
						$B.request({
							data:{idList : prs.id},
							url:$B.getHttpHost(ctxPath) + "menu/delete",
							ok:function(message, data){								
								queryTree(rootId);
							}
						});
					}
				});
			}				
		};
		function queryTree(pid){
			$B.request({
				data:{pid:pid},
				url:$B.getHttpHost(ctxPath) + "menu/query",
				ok:function(message, data){
					createTree(data);
				}
			});
		}
		function createTree(treeJson){
			if(tree){
				tree.clear();
			}
			if(treeJson.length === 0){
				$tree.append("<li>[(${Lang.common_dataEmpty})]</li>");
				return;
			}
		    tree = new $B.Tree($tree, {
                data: treeJson, //'数据'	
                toolbar:true,
                nodeParentIcon: 'fa-folder-empty', //父节点图标关闭状态
                nodeParentOpenIcon: 'fa-folder-open-empty', //打开状态图标
                leafNodeIcon: 'fa-doc', //子节点图标 
                checkbox: false,
                fontIconColor: '#5F52E3'
	        });
		}
		$(function(){
			var treeJson = [(${treeJson})];
			$tree = $("#tree");
			rootId = '[(${pid})]';
			createTree(treeJson);
			$("#addRoot").click(function(){
					var opts = {
						dataType:'html',
						title:'[(${menu_childmrg})]',
						width:700,
						height:400,
						content: $B.getHttpHost(ctxPath) + "menu/page/form?pid="+rootId
					};					
					win = $B.window(opts);
			});
		});	
	</script>
</body>
</html>